package com.springboot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springboot.entity.User;
import com.springboot.mapper.UserMapper;
import com.springboot.service.UserService;
@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private UserMapper userMapper;
	@Override
	public void createUser(String name, Integer age) {
		jdbcTemplate.update("insert into  test_user (name,age) values(?,?);", name, age);	
	}

	@Override
	public User getUserByMybatis(String name) {
		User user=userMapper.findByName(name);
		System.out.println(user.getName()+"::::"+user.getAge());
		return user;
	}

	@Override
	public void createUserByMybatis(String name, Integer age) {
		userMapper.insert(name, age);
	}

	@Override
	public PageInfo<User> findUserList(int page, int size) {
		// 开启分页插件,放在查询语句上面
		PageHelper.startPage(page, size);
		List<User> listUser = userMapper.findUserList();
		// 封装分页之后的数据
		PageInfo<User> pageInfoUser = new PageInfo<User>(listUser);
		return pageInfoUser;

	}

}
